package com.weasel.security.escape;

import com.weasel.security.helper.XssEscapeHelper;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

/**
 * Created by Dylan on 2015/12/16.
 */
public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper {
    /**
     * Constructs a request object wrapping the given request.
     *
     * @param request
     * @throws IllegalArgumentException if the request is null
     */
    public XssHttpServletRequestWrapper(HttpServletRequest request) {
        super(request);
    }

    @Override
    public String[] getParameterValues(String name) {
        String[] parameters = super.getParameterValues(name);
        if(null != parameters){
            for(int i = 0;i < parameters.length;i++){
                parameters[i] = XssEscapeHelper.xssEscape(parameters[i]);
            }
        }
        return parameters;
    }

    @Override
    public String getParameter(String name) {
        String parameter =  super.getParameter(name);
        parameter = XssEscapeHelper.xssEscape(parameter);
        return parameter;
    }
}
